#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=998244353;
int a[maxn];
int diff[maxn];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

	int n,m;
	cin >> n >> m;
	for(int j=1;j<=m;j++)
	{
		int c,b;
		cin >> c >>b;
		diff[c]=diff[c]+1;
		diff[b+1]=diff[b+1]-1;
		for(int i=c;i<=b;i++)
		{
			a[i]=a[i-1]+diff[i];
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]==m)
		{
			ans=ans+1;
		}
	}
	cout << ans << endl;
	return 0;
}
